int timeRequiredToBuy(int* tickets, int ticketsSize, int k){
    for(int i=0;i<ticketsSize;i++){
      if((i<k)&&(tickets[i]>tickets[k])){
        tickets[i]=tickets[k];
      }
      if((i>k)&&tickets[i]>=tickets[k]){
        tickets[i]=tickets[k]-1;
      }
    }
    int cnt=0;
    for(int i=0;i<ticketsSize;i++){
      cnt+=tickets[i];
    }
    return cnt;
}
